﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ServicesSheet_SCGYList3 : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent();

            Master.DataSource = WMaster;


            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "~/Help/ServicesSheet/私车公用申请的管理.htm";
            master.PageName = "私车公用财务登记";
            master.PicUrl = "";
            master.IntiBar();
        }
        //this.WebClientQuery1.Show(this.Panel1);
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServicesSheet_SCGYList3));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "ServiceSheet.Services_SCGY";
        this.WMaster.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    protected void WebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdPrint")
        {
            string whereIn = "(";
            for (int i = 0; i < this.wgvMaster.Rows.Count; i++)
            {
                CheckBox cbPrint = (CheckBox)this.wgvMaster.Rows[i].FindControl("CheckBox1");
                if (cbPrint.Checked == true)
                {
                    string usecarId = this.wgvMaster.Rows[i].Cells[3].Text;
                    whereIn += usecarId + ",";
                }
            }
            if (whereIn == "(")
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('请在要打印的数据前面打钩！')", true);
                return;
            }
            if (whereIn.EndsWith(","))
            {
                whereIn = whereIn.Remove(whereIn.Length - 1);
            }
            whereIn += ")";
            this.Response.Redirect("SCGYPrint.aspx?printId=" + whereIn);

        }
    }

    public override void DataBind()
    {
        wgvMaster.DataBind();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        QueryData();
    }

   

    protected bool IsVisable(object Indata)
    {
        bool ret = Convert.ToBoolean(Indata);

        return !ret;
    }
    protected void Query_Click(object sender, EventArgs e)
    {
        QueryData();
    }

    private void QueryData()
    {
        string Sql = "";
        string strYear = "";
        string strMonth = "";
        string strCarId = "";
        string strLock = "";
        string strEmpId = "";


        strYear = DSelYearMonth1.SelectYear;
        strMonth = DSelYearMonth1.SelectMonth;
        strCarId = TextBox1.Text.Trim();
        strLock = SelLock.SelectedValue;
        strEmpId = SelUser.EmpName;

        if (strYear == "0" || strYear == string.Empty) strYear = "";
        if (strYear.Length == 0)
        {
            strMonth = "";
        }
        else
        {
            if (strMonth == "0" || strMonth == string.Empty) strMonth = "";
        }

        Sql = " (1=1)";
        if (strEmpId.Length > 0) Sql = Sql + string.Format(" AND (Employees.EmpName like '%{0}%') ", strEmpId);
        if (strYear.Length > 0) Sql = Sql + string.Format(" AND (YEAR(Services_SCGY.UDate) = {0}) ", strYear);
        if (strMonth.Length > 0) Sql = Sql + string.Format(" AND (MONTH(Services_SCGY.UDate) = {0})", strMonth);
        if (strCarId.Length > 0) Sql = Sql + string.Format(" AND (Services_SCGY.Id = {0})", strCarId);
        if (strLock != "9") Sql = Sql + string.Format(" AND (Services_SCGY.Finance = {0})", strLock);

        InitializeComponent();
        WMaster.SetWhere(Sql);
        Master.DataSource = WMaster;
    }
}
